#include "tracker_display.h"
#include "ui_tracker_display.h"

tracker_display::tracker_display(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::tracker_display)
{
    ui->setupUi(this);

    QStringList labels;
    labels << trUtf8("下水位")<<trUtf8("上水位")<<trUtf8("冷却水")<<trUtf8("压力到位")\
           <<trUtf8("加水")<<trUtf8("加热")<<trUtf8("进气")<<trUtf8("排气")<<trUtf8("真空泵")<<trUtf8("回气")
           <<trUtf8("前门关到位")<<trUtf8("前门开到位")<<trUtf8("前门密封")\
           <<trUtf8("后门开到位")<<trUtf8("后门关到位") <<trUtf8("后门密封")
           <<trUtf8("开前门")<<trUtf8("关前门")<<trUtf8("封前门")<<trUtf8("解封前门")\
           <<trUtf8("开后门")<<trUtf8("关后门")<<trUtf8("封后门")<<trUtf8("解封后门") ;//<<trUtf8("超压")

    ui->tableWidget->setVerticalHeaderLabels (labels );
    QObject:: connect( ui->tableWidget, SIGNAL(cellClicked(int,int)),
                       this, SLOT(display_currentcolumn_data(int, int) ) );
    ui->tableWidget->setRowCount(24);
    pagenum=1;
}



tracker_display::~tracker_display()
{
    delete ui;
}


void tracker_display::display_data()
{

    int coln=track->track_data_list.size();
    ui->column_counter_label->setText(QString::number(coln));
    ui->tableWidget->setColumnCount(coln+1);
    for(uint col=0;col<coln;col++)
    for(uchar row=0;row<24;row++)

    {
        if(ui->tableWidget->item(row,col)==0) ui->tableWidget->setItem(row,col,new QTableWidgetItem);
        set_column_data(track->track_data_list[col][3],row,col);

    }

}


void  tracker_display::read_page(int page)
{
    listpage=track->track_data_list.mid(60*(page-1),60);

}


void tracker_display::set_column_data(int IO_data,int row,int col)
{
   // for(uchar row=0;row<24;row++)
    {
    if(IO_data & (0x0001<<row))
 {
    switch(row%3)
    {
    case 0:ui->tableWidget->item(row,col)->setBackgroundColor(QColor::fromRgb(255,0,0));break;
    case 1:ui->tableWidget->item(row,col)->setBackgroundColor(QColor::fromRgb(0,255,0));break;
    case 2:ui->tableWidget->item(row,col)->setBackgroundColor(QColor::fromRgb(0,0,255));break;

    }
 }
    }

}


void tracker_display::display_currentcolumn_data(int row, int column)
{
    if(column < track->track_data_list.size())
    {
        ui->temperature_label->setText(QString::number(track->track_data_list[column][2]));
        ui->pressure_label->setText(QString::number(track->track_data_list[column][1]));
        ui->timeEdit->setTime(track->startTime.time().addSecs(track->track_data_list[column][0]) );
        ui->column_counter_label->setText(QString::number(track->track_data_list[column][4]));

    }
}

void tracker_display::on_nextpage_btn_clicked()
{
    read_page( ++pagenum);
}
